#include<bits/stdc++.h>
using namespace std;
namespace my_std{
	#define ll int
	#define bl bool
	ll my_pow(ll a,ll b,ll mod){
		ll res=1;
		if(!b) return 1;
		while(b){
			if(b&1) res=(res*a)%mod;
			a=(a*a)%mod;
			b>>=1;
		}
		return res;
	}
	ll qpow(ll a,ll b){
		ll res=1;
		if(!b) return 1;
		while(b){
			if(b&1) res*=a;
			a*=a;
			b>>=1;
		}
		return res;
	}
	#define db double
	#define pf printf
	#define pc putchar
	#define fr(i,x,y) for(register ll i=(x);i<=(y);i++)
	#define pfr(i,x,y) for(register ll i=(x);i>=(y);i--)
	#define go(u) for(ll i=head[u];i;i=e[i].nxt)
	#define enter pc('\n')
	#define space pc(' ')
	#define fir first
	#define sec second
	#define MP make_pair
	#define il inline
	#define inf 8e18
	#define random(x) rand()*rand()%(x)
	#define inv(a,mod) my_pow((a),(mod-2),(mod))
	#define getchar gc
	il char gc(){static char buf[1000000],*p1=buf,*p2=buf;return p1==p2&&(p2=(p1=buf)+fread(buf,1,1000000,stdin),p1==p2)?EOF:*p1++;}
	il ll read(){ll sum=0,f=0;char ch=getchar();for(;!isdigit(ch);ch=getchar())f|=(ch=='-');for(;isdigit(ch);ch=getchar())sum=((sum<<1)+(sum<<3)+(ch^48));return f?-sum:sum;}
	il void write(ll x){
		if(x<0){
			x=-x;
			pc('-');
		}
		if(x>9) write(x/10);
		pc(x%10+'0');
	}
	il void writeln(ll x){
		write(x);
		enter;
	}
	il void writesp(ll x){
		write(x);
		space;
	}
}
using namespace my_std;
#define LC x<<1
#define RC x<<1|1
vector<ll> vec[400040];
pair<ll,ll> st[200020];
ll n,m,q,lst[200020],fa[200020],siz[200020],top=0,ans;
struct node{
	ll u,v;
}e[200020];
void ins(ll x,ll l,ll r,ll ql,ll qr,ll v){
	if(ql<=l&&r<=qr){
		vec[x].push_back(v);
		return;
	}
	ll mid=(l+r)>>1;
	if(ql<=mid) ins(LC,l,mid,ql,qr,v);
	if(mid<qr) ins(RC,mid+1,r,ql,qr,v);
}
ll find(ll x){
	if(x==fa[x]) return x;
	return find(fa[x]);
}
il void merge(ll x,ll y){
	x=find(x);
	y=find(y);
	if(x==y) return;
	if(siz[x]<siz[y]) swap(x,y);
	fa[y]=x;
	siz[x]+=siz[y];
	st[++top]=MP(x,y);
	ans--;
}
void solve(ll x,ll l,ll r){
	ll tmp=top;
	fr(i,0,(ll)vec[x].size()-1){
		ll id=vec[x][i];
		merge(e[id].u,e[id].v);
	}
	if(l==r){
		if(ans==1){
			pc('Y');
			pc('E');
			pc('S');
			enter;
		}
		else{
			pc('N');
			pc('O');
			enter;
		}
	}
	else{
		ll mid=(l+r)>>1;
		solve(LC,l,mid);
		solve(RC,mid+1,r);
	}
	while(top>tmp){
		ll u=st[top].fir,v=st[top].sec;
		fa[v]=v;
		siz[u]-=siz[v];
		top--;
		ans++;
	}
}
int main(){
	freopen("graph.in","r",stdin);
	freopen("graph.out","w",stdout);
	n=read();
	m=read();
	fr(i,1,m){
		e[i].u=read();
		e[i].v=read();
	}
	q=read();
	fr(i,1,q){
		ll k=read();
		while(k--){
			ll x=read();
			if(lst[x]<(i-1)) ins(1,1,q,lst[x]+1,i-1,x);
			lst[x]=i;
		}
	}
	fr(i,1,m) if(lst[i]<q) ins(1,1,q,lst[i]+1,q,i);
	fr(i,1,n) fa[i]=i;
	fr(i,1,n) siz[i]=1;
	ans=n;
	solve(1,1,q);
}
